<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="bit.util.ConnectionContext"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
int no = Integer.parseInt(request.getParameter("no"));

String sql = "SELECT * FROM champ WHERE no = ?";
Connection conn = ConnectionContext.getConnection();
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, no);
ResultSet rs = pstmt.executeQuery();

String name = null;
String type = null;
int health = -1;
int damage = -1;

if (rs.next()) {
	name = rs.getString("name");
	type = rs.getString("type");
	health = rs.getInt("health");
	damage = rs.getInt("damage");
}

rs.close();
pstmt.close();
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>챔프 정보 수정</title>
<script type="text/javascript">
	function onlyDigit(e) {
		if (console) {
			console.log(e);
			console.log("keyCode = " + e.keyCode);
			console.log("which = " + e.which);
			console.log("charCode = " + e.charCode);
		}
		// "0"의 keyCode = 48, "9"의 keyCode = 57
		if (e.keyCode > 47 && e.keyCode < 58)
			return true;
		else if (e.keyCode > 36 && e.keyCode < 41)	// 방향 키
			return true;
		else if (e.keyCode == 9)	// 탭 키
			return true;
		else
			return false;
	}
</script>
</head>
<body>

<form action="editx.jsp" method="post">
<input type="hidden" name="no" value="<%= no %>" />
<table border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td>챔프명</td>
		<td><input type="text" name="name" size="10" 
			value="<%= name != null ? name : "" %>" /></td>
		<td>타입</td>
		<td><input type="text" name="type" size="10" 
			value="<%= type != null ? type : "" %>" /></td>
	</tr>
	<tr>
		<td>체력</td>
		<td><input type="text" name="health" size="10" 
			value="<%= health != -1 ? health : "" %>" 
			onkeydown="return onlyDigit(event);" /></td>
		<td>공격력</td>
		<td><input type="text" name="damage" size="10" 
		value="<%= damage != -1 ? damage : "" %>" 
		onkeydown="return onlyDigit(event);" /></td>
	</tr>
	<tr>
		<td colspan="4" align="center">
			<input type="submit" value="챔프 수정" />
		</td>
	</tr>
</table>

</form>

<a href="list.jsp">챔프 목록 보기</a>

</body>
</html>